<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@ page import="java.sql.*" %>	
<%@page import="net.sf.json.JSONObject"%>

<%String callback = request.getParameter("callback");%>
<%=callback %> (<%
	
	String id = request.getParameter("id");
	String push = request.getParameter("push");
	String vibrate = request.getParameter("vibrate");
	
	if (vibrate == null){
		vibrate = "0";
	}
	
	if (push == null){
		push = "1";
	}
	
	JSONObject jo = new JSONObject();
	Connection conn = null;
	PreparedStatement pstmt = null;
	
	try {

		Class.forName("com.mysql.jdbc.Driver");
		conn = DriverManager.getConnection("jdbc:mysql://localhost/itscreater", "itscreater", "campus123");
		
			String update = "update gcm set Push:= ?, Vibrate:= ?" +
					"where ID = ?;";
			pstmt = conn.prepareStatement(update);
			pstmt.setString(1, push);
			pstmt.setString(2, vibrate);
			pstmt.setString(3, id);
			pstmt.executeUpdate();
			
			jo.put("success", "true");
			out.print(jo);
	
	} catch (Exception e) {

	}
	finally{
		try{
			pstmt.close();
		}
		catch (Exception ignored){
		}
		try{
			conn.close();
		}
		catch (Exception ignored){
		}
	}
%>);